import { request } from "@/utils";

interface Captcha {
  captchaImg: string;
  key: string;
}
interface ValidCaptcha {
  key: string;
  code: string;
}
interface PwdLogin {
  account: string;
  password: string;
  captchaCode: string;
  key: string;
}
export const authApi = {
  /** 获取图形验证码 */
  captcha: () =>
    request.get<Captcha>("/auth/captcha", null, { noNeedToken: true }),
  /** 获取手机验证码 */
  codeByPhone: (phone: string) =>
    request.get("/auth/phone-code", { phone }, { noNeedToken: true }),
  /** 获取邮箱验证码 */
  codeByEmail: (email: string) =>
    request.get("/auth/email-code", { email }, { noNeedToken: true }),
  /** 获取邮箱验证码 */
  validCaptcha: (data: ValidCaptcha) =>
    request.post("/auth/valid-captcha", data, { noNeedToken: true }),
  /** 账号密码登录，获取token */
  login: (data: PwdLogin) =>
    request.post("/auth/login", data, { noNeedToken: true }),
  /** 退出登录删除token，请使用userStore.logout() */
  logout: () => request.post("/auth/logout"),
  /** 刷新token */
  refreshToken: () => request.post("/auth/refresh-token"),
  /** 获取keepAlive的组件名 */
  getKeepAliveRoute: () => request.get<string[]>("/auth/keepalive"),
};
